package mao.thinkinjava.array;

public class CountingGenerator {
    //private static Random rm = new Random(47);
    public static class Character implements Generator<java.lang.Character>{
        public  static char[] chars = ("abcdefgh"+"ABCDEFG").toCharArray();
        int value = -1;
        @Override
        public java.lang.Character generate() {
            value=(value+1)%chars.length;
            return chars[value];
        }
    }

    public static class String implements Generator<java.lang.String> {
        //后面RandomGenerator这里可以进行替换
         Generator<java.lang.Character> cg = new Character();
        private int length = 4;
        public String(){}
        public String(int length){this.length = length;}
        @Override
        public java.lang.String generate() {
            char[] res = new char[length];
             //错误写法，不能用于赋值
//            for(char c : res){
//                c = cg.generate();
//            }
            for(int i=0;i<length;i++){
                res[i] = cg.generate();
            }
            return new java.lang.String(res);
        }
    }
}
